T
CSharpTest.Net
DisposingList<T> Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace : DisposingList<T> Class

Glossary Item Box

Disposes of each element in the collection when the collection is disposed.

Object Model

DisposingList<T> ClassT Class

Syntax

Visual Basic (Declaration) 
Public Class DisposingList(Of T As IDisposable) 
   Inherits System.Collections.Generic.List(Of T)
C# 
public class DisposingList<T> : System.Collections.Generic.List<T> 
where T: IDisposable

Type Parameters

T

Example

Library/Library.Test/TestStreamCache.cs

C#Copy Code
using (TempFile tempFile = new TempFile())
{
    FileStreamFactory factory = new FileStreamFactory(tempFile.TempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
    using (DisposingList<Stream> open = new DisposingList<Stream>())
    {
        for( int i = 0; i < 50; i++ )
            open.Add(factory.Create());
    }
}
VB.NETCopy Code
Using tempFile As New TempFile()
    Dim factory As New FileStreamFactory(tempFile.TempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
    Using open As New DisposingList(Of Stream)()
        Dim i As Integer = 0
        While i < 50
            open.Add(factory.Create())
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While
    End Using
End Using

Inheritance Hierarchy

System.Object
   System.Collections.Generic.List<T>
      CSharpTest.Net.Collections.DisposingList<T>
         CSharpTest.Net.Collections.DisposingList

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys